package com.ibeeking.found.open.b.rest.controller.v1;

import com.ibeeking.found.open.api.common.dto.CouponInfoDTO;
import com.ibeeking.found.open.api.common.query.CouponInfoQuery;
import com.ibeeking.found.open.b.rest.service.ICouponService;
import com.ibeeking.found.open.service.common.param.CouponVerificationQRParam;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @ClassName CouponController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/v1/open/api/coupon")
public class CouponOpenController {

    @Resource
    private ICouponService couponServiceImpl;

    /**
     * erp小程序调用
     *
     * @param marketCode
     * @param query
     * @return
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "券详情查询")
    @PostMapping(value = "/info/{marketCode}")
    public CouponInfoDTO couponInfo(@PathVariable @NotNull(message = "商场编码不能为空") String marketCode, @RequestBody @Validated CouponInfoQuery query) {
        return couponServiceImpl.couponInfoById(marketCode, query);
    }

    /**
     * erp小程序调用
     *
     * @param marketCode
     * @param param
     * @return
     */
    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "核销优惠券")
    @PostMapping(value = "/verification/{marketCode}")
    public Boolean verificationById(@PathVariable @NotNull(message = "商场编码不能为空") String marketCode, @RequestBody @Validated CouponVerificationQRParam param) {
        return couponServiceImpl.verificationById(marketCode, param);
    }
}
